<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>作用域插槽</title>
</head>
<body>
  <div><h3>父组件替换插槽的标签，但是内容由子组件来提供</h3></div>
  <div id="app">
    {{message}}
    <cpn></cpn>
    <cpn>这里无法直接拿到languages数组</cpn>
    <cpn>
      <template slot-scope="slot">
        <span v-for="(item, index) in slot.yuhao" :key="index">{{item}} -</span>
      </template>
    </cpn>
  </div>
 
  <template id="cpn">
    <div>
      <slot :yuhao="languages"> <!--这里就可以在上面使用languages数组-->
        <ul>
          <li v-for="(item, index) in languages" :key="index">{{item}}</li>
        </ul>
      </slot>
    </div>
  </template>

  <script src="../js/vue.js"></script>
  <script>
    const app = new Vue({
      el: '#app',
      data: {
        message: '你好啊',
      },
      components: {
        cpn: {
          template: '#cpn',
          data() {
            return {
              languages: ['java','c','c#','python','go'],
            }
          }
        }
      }
    })
  </script>
</body>
</html>